#!/bin/bash

# $Header: /opt/unixmon/tools/DNS/RCS/nslookupall,v 1.1 2012/11/27 07:50:51 yajin Exp $
# Author: yang.jin@ebay.com


export PATH=/bin:/usr/bin

if [ "X$(uname -s)" == "XSunOS" ]; then
    GREP="/usr/xpg4/bin/grep"
    SED="/usr/xpg4/bin/sed"
else
    GREP="/bin/grep"
    SED="/bin/sed"
fi

DNS_SERVERS_LIST="/etc/named/IT_DNS_SERVERS"

if [ ! -f $DNS_SERVERS_LIST ]; then
        echo -e "The configuration file \"$DNS_SERVERS_LIST\" does not exist." >&2
        exit 2
fi

. $DNS_SERVERS_LIST

paras=""

while [ $1 ]; do
	paras=$(echo -e "$paras $1")
	shift
done

if [ "X${paras}" == "X" ]; then 
	echo "$(basename $0)	query on each IT DNS server
Usage:	$(basename $0) nslookup-options
" >&2
	exit 1
fi

for host in $(echo $DNS_PRIMARY_MASTER $DNS_PSEUDO_MASTERS $DNS_SLAVES); do
	echo -e "\n* Querying $host..." 
	/opt/bind/bin/nslookup -fail $paras $host | $GREP -v -E "^Server:[[:space:]]+|^Address:[[:space:]]+.*#53$|^[[:space:]]*$"
done

